import Vue from "vue";
import App from "./App";

import api from "api/index.js";
import util from "@/utils/index.js";
import i18n from "@/locale/index.js";
// #ifdef H5
import jweixin from "@/utils/jweixin.js";
// #endif
import store from "./store/index.js";
import banner from "@/components/banner.vue";
import column from "@/components/column.vue";
import fixed from "@/components/fixed.vue";
import search from "@/components/search.vue";
import auth from "@/components/auth.vue";
import tab from "@/components/tab.vue";
import abnor from "@/components/abnor.vue";
import loadMore from "@/components/load-more.vue";
import upload from "@/components/upload.vue";
import minCountdown from "@/components/min-countdown.vue";
import uniNavBar from "@/components/uni-nav-bar.vue";
import uniPopup from "@/components/uni-popup.vue";
import commonPopup from "@/components/common-popup.vue";
import loginInfo from "@/components/login-info.vue";
import fixBottomButton from "@/components/fix-bottom-button.vue";
import uniSegmentedControl from "@/components/uni-segmented-control.vue";
import back from "@/components/back.vue";
import func from "@/node_modules/uview-ui/func.js";
import wanlshop from "@/utils/wanlshop/wanlshop.js";
import request from "@/utils/network.js";
// import wx from 'https://res.wx.qq.com/open/js/jweixin-1.2.0.js'
// 系统配置
import wanlshop_function from "./common/wanlshop_function";
import Base64 from "./common/base64";

// Vue.prototype.$wx = wx

Vue.component("banner", banner);
Vue.component("column", column);
Vue.component("fixed", fixed);
Vue.component("search", search);
Vue.component("auth", auth);
Vue.component("tab", tab);
Vue.component("abnor", abnor);
Vue.component("loadMore", loadMore);
Vue.component("upload", upload);
Vue.component("minCountdown", minCountdown);
Vue.component("uniNavBar", uniNavBar);
Vue.component("uniPopup", uniPopup);
Vue.component("commonPopup", commonPopup);
Vue.component("loginInfo", loginInfo);
Vue.component("fixBottomButton", fixBottomButton);
Vue.component("uniSegmentedControl", uniSegmentedControl);
Vue.component("back", back);
Vue.use(func);

Vue.prototype.$api = api;
Vue.prototype.$util = util;
Vue.prototype._i18n = i18n;
// copy
Vue.prototype.$wanlshop = wanlshop;
Vue.prototype.$base64 = new Base64();

// #ifdef H5
Vue.prototype.$jweixin = jweixin;
// #endif
Vue.config.productionTip = false;
import uView from "uview-ui";
Vue.use(uView);
import httpInterceptor from "@/common/http.interceptor.js";
Vue.use(httpInterceptor, app);
App.mpType = "app";
uni.$store = store;
uni.$api = api;
uni.$util = util;

Vue.prototype.$request = request;
Vue.prototype.$showImg = (url = "") => {
    if (!url) return url;
    if (url.indexOf("http") !== -1) return url;
    return request.imgHost + url;
};

// 全局商品链接
// Vue.prototype.onGoods = function(id) {wanlshop.to(`/pages/product/goods?id=${id}`)}
Vue.prototype.onGoods = function (id) {
    wanlshop.to(`/pages/product/goods?id=${id}`);
};

// 全局订单详情
Vue.prototype.orderDetails = function (order_id) {
    wanlshop.to(`/pages/user/order/details?id=${order_id}`);
};

// 全局店铺链接
Vue.prototype.onShop = function (id) {
    // wanlshop.to(`/pages/shop/index?id=${id}`)
    wanlshop.to(`/dabai/pages/aShop/aShop?id=${id}`);
};

// 全局店铺链接
Vue.prototype.onShopGoods = function (id) {
    wanlshop.to(`/pages/shop/product/list?shop_id=${id}`);
};

//  全局物流动态
Vue.prototype.onLogistics = function (order_id) {
    wanlshop.to(`/pages/user/order/logistics?id=${order_id}`);
};

// 全局联系方式 1.0.2升级
Vue.prototype.toChat = function (shop_id, goods = null) {
    goods
        ? wanlshop.to(`/pages/notice/chat?shop_id=${shop_id}&goods=${JSON.stringify(goods)}`)
        : wanlshop.to(`/pages/notice/chat?shop_id=${shop_id}`);
};

// 打开详情页
Vue.prototype.onDetails = function (id, title) {
    wanlshop.to(`/pages/article/details?id=${id}&title=${title}`);
};

// 打开广告
Vue.prototype.onAdvert = function (data) {
    data.url && !/^(http|https):\/\/.+/.test(data.url)
        ? on(data.url)
        : wanlshop.to(`/pages/article/advert?id=${data.id}`);
};

// 打开直播
Vue.prototype.onLive = function (id) {
    auth(`/pages/apps/find/details/live?id=${id}`);
};

// 打开发现
Vue.prototype.onFind = function (data, comments = null) {
    if (data.type == "live") {
        this.onLive(data.live_id);
    } else if (data.type == "video") {
        wanlshop.to(`/pages/apps/find/details/video?id=${data.id}`);
    } else {
        if (comments) {
            wanlshop.to(`/pages/apps/find/details/details?id=${data.id}&afferent=comments`);
        } else {
            wanlshop.to(`/pages/apps/find/details/details?id=${data.id}`);
        }
    }
};
// 时间戳转换 -- 个人中心和会员页使用了
Vue.filter("formatTimestamp", function (timestamp) {
    // 假设这是你得到的10位时间戳
    var tenDigitTimestamp = timestamp; // 这里需要替换为实际的数字值
    // 转换为毫秒级时间戳
    var millisecondTimestamp = parseInt(tenDigitTimestamp) * 1000;
    // 使用毫秒级时间戳创建Date对象
    var dateObject = new Date(millisecondTimestamp);
    const date = new Date(dateObject);
    const year = date.getFullYear();
    const month = ("0" + (date.getMonth() + 1)).slice(-2);
    const day = ("0" + date.getDate()).slice(-2);
    const hours = ("0" + date.getHours()).slice(-2);
    const minutes = ("0" + date.getMinutes()).slice(-2);
    const seconds = ("0" + date.getSeconds()).slice(-2);

    return `${year}-${month}-${day}`;
    // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
});

const app = new Vue({
    ...App,
    store,
    i18n,
});
app.$mount();
// @import "@/styles/index.wxss";
